package com.simba.server.commands.impl.fetch;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

import java.sql.ResultSet;
import java.util.List;

public class FetchSlotPackByNoSyncCmd implements ICommand {
    public static final String NAME = "FetchSlotPackByNoSyncCmd";
    private final List<Integer> idList;
    private final String sql = "select * from tt_slot_pack_info where syncFlag=0 limit 1000;";

    public FetchSlotPackByNoSyncCmd(List<Integer> idList)
    {
        this.idList = idList;
    }
    @Override
    public String getName() {
        return FetchSlotPackByNoSyncCmd.NAME;
    }

    @Override
    public Boolean run(Object params) {
        Boolean ret = false;

        if (!(params instanceof DbOperator))
        {
            return ret;
        }

        try
        {
            DbOperator dbOperator = (DbOperator) params;
            dbOperator.prepareStatement(this.sql);

            ResultSet rs = dbOperator.executeQuery();

            while (rs.next())
            {
                int id = rs.getInt("id");
                idList.add(id);
            }

            ret = true;
        }
        catch (Exception ex)
        {
            ret = false;
        }

        return ret;
    }
}
